package com.macro.mall.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsFunParam;
import com.macro.mall.model.BmsFun;
import com.macro.mall.service.BmsFunService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 添加浙东
 * Created 2024/8/10.
 *
 */
@Controller
@Api(tags = "BmsFun")
@Tag(name = "BmsFun", description = "浙东趣事")
@RequestMapping("/bmsFun")
public class BmsFunController {
    
    @Autowired
    private BmsFunService bmsFunService;
    
    @ApiOperation("添加浙东趣事")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsFunParam bmsFunParam) {
        int count = bmsFunService.create(bmsFunParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
    
    @ApiOperation("修改浙东趣事")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsFunParam bmsFunParam) {
        int count = bmsFunService.update(bmsFunParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
    
    @ApiOperation("分页浙东趣事")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsFun>> getList(@RequestBody BmsFunParam bmsFunParam) {
        List<BmsFun> bmsFunList = bmsFunService.getList(bmsFunParam);
        return CommonResult.success(CommonPage.restPage(bmsFunList));
    }
    
    @ApiOperation("根据id获取浙东趣事")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsFun> getItem(@PathVariable Long id) {
        BmsFun bmsFun = bmsFunService.getItem(id);
        return CommonResult.success(bmsFun);
    }
    
    @ApiOperation("删除浙东趣事")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> delete(@RequestParam("ids") List<Long> ids) {
        int count = bmsFunService.delete(ids);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
}
